<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="com.powroznik.tracker.engine.services.Account"%>
<%@page import="com.powroznik.tracker.engine.services.User"%>
<%@page import="com.powroznik.tracker.liferay.portlet.Client"%>

<%@ taglib prefix="aui" uri="http://liferay.com/tld/aui"%>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0"%>

<portlet:defineObjects />

<portlet:renderURL var="viewURL">
	<portlet:param name="jspPage" value="/html/connectdeviceportlet/view.jsp" />
</portlet:renderURL>

<%
	Client client = Client.getInstance(request);
	client.setUserKey(renderRequest.getRemoteUser());
	Account account = client.getAccount();

	String code1 = renderRequest.getParameter("code1");
	String description = renderRequest.getParameter("description");
	if (StringUtils.isNotBlank(code1)
			&& StringUtils.isNotBlank(description)) {
		client.connectDevice(code1, description);
	}
%>

<%
	if (account == null) {
%>

<p>Your user does not appear to be linked to any account. In order
	to use all features of this application, you first need to register
	your account.</p>

<%
	} else {
%>

<p>Connect your devices to your account:</p>

<aui:form action="<%=viewURL%>" method="post">
	<aui:layout>
		<aui:column>
			<aui:input label="code" name="code1" type="text" />
			<aui:input label="description" name="description" type="text" />
			<aui:button type="submit" value="Connect" />
		</aui:column>
	</aui:layout>
</aui:form>

<%
	}
%>